package com.itstyle.seckill.topic.desinger.design_cj.composite;

import java.util.ArrayList;

/**
 * @Auther: liuwenxiang
 * @Date: 2019/9/18 20:00
 * @Description:
 */
public class Composite implements Component {

    private ArrayList<Component> children=new ArrayList<Component>();
    @Override
    public void add(Component c)
    {
        children.add(c);
    }
    @Override
    public void remove(Component c)
    {
        children.remove(c);
    }
    @Override
    public Component getChild(int i)
    {
        return children.get(i);
    }
    @Override
    public void operation()
    {
        for(Object obj:children)
        {
            ((Component)obj).operation();
        }
    }
}
